package com.pzhu.servlet;

import com.pzhu.controller.BookController;
import com.pzhu.controller.impl.BookControllerImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class DeleteBookServlet extends HttpServlet {
    private BookController bookController = new BookControllerImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session =req.getSession();
        if (session.getAttribute("login") == null) {
            req.getRequestDispatcher("/main").forward(req, resp);
            return;
        }
        for (String id : req.getParameter("id").split(",|，|、")) {
            System.out.println(id);
            bookController.deleteBook(Long.valueOf(id));
        }
        req.getRequestDispatcher("/show-all-books").forward(req, resp);
        return;
    }
}
